-- list users with elevated permissions in all databases on the server
SET IMPLICIT_TRANSACTIONS OFF
BEGIN TRY
	CREATE TABLE #results (
		[Server]			SYSNAME NOT Null,
		[Database]			SYSNAME NOT Null,
		[DB Role]			SYSNAME NOT Null,
		[DB Role Type]		SYSNAME NOT Null,
		[Role Member]		SYSNAME NOT Null,
		[Role Member Type]	SYSNAME NOT Null)
END TRY BEGIN CATCH
	TRUNCATE TABLE #results
END CATCH
INSERT INTO #results EXEC sp_msforeachdb 'USE [?];
	SELECT @@SERVERNAME, DB_NAME(), r.name, r.type_desc, m.name, m.type_desc
	  FROM sys.database_principals r
		INNER JOIN sys.database_role_members rm ON (r.principal_id = rm.role_principal_id)
		INNER JOIN sys.database_principals m ON (rm. member_principal_id = m.principal_id)
	  WHERE r.name NOT IN (''db_datareader'', ''db_datawriter'') AND m.name NOT IN (''dbo'')'
SELECT * FROM #results ORDER BY 1,2,3,5
GO